package com.example.administrator.androidhomework2;

import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {
    EditText mEtHeight;
    RadioGroup mRgSex;
    Button mBtnCompute;
    TextView mtvresult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mEtHeight = findViewById(R.id.et_height);

        mRgSex = findViewById(R.id.rg_sex);

        mBtnCompute = findViewById(R.id.btn_compute);
        mBtnCompute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int height = Integer.parseInt(mEtHeight.getText().toString());
                int id = mRgSex.getCheckedRadioButtonId();
                if(id == R.id.rb_male){
                    int standardWeight = (int)((height - 100)*0.9);
                    mtvresult.setText("标准体重是:"+standardWeight + "kg");
                }else if (id == R.id.rd_famale){
                    int standardWeight = (int)((height - 100)*0.9-2.5);
                    mtvresult.setText("标准体重是:"+standardWeight + "kg");
                }

            }
        });
    }
}
